<template>
  <page-header-wrapper>
    <page-tab-list>
      <SearchBox @search="search" @exportOL="exportOL" :exporting="exporting" :is_cloud="is_cloud"></SearchBox>
    </page-tab-list>
    <a-card :bordered="false">
      <div class="table-operator">
        <a-radio-group :defaultValue="-1" v-model="queryParam.status" @change="onOptionChange">
          <a-radio-button v-for="(item, index) in options" :key="index" :value="item.value">
            {{ item.title }}
          </a-radio-button>
        </a-radio-group>
      </div>
      <a-spin :spinning="spinning">
        <ListTable ref="listTable" :list_th="list_th" :pagaData="pagaData" @triggerAction="listActions"> </ListTable>
      </a-spin>
      <div style="float: right">
        <Pagination
          v-model="pageParams.pageNo"
          :total="totalCount"
          :show-total="(total) => `总数：${total}`"
          show-less-items
        />
      </div>
    </a-card>

    <ModifyLogistics
      :expressList="expressList"
      :orderId="orderId"
      :orderInfo="orderInfo"
      :visible.sync="isShowModifyLogistics"
    ></ModifyLogistics>
    <SendModal
      :visible.sync="isShowSendModal"
      :expressList="expressList"
      :orderId="orderId"
      :orderInfo="orderInfo"
      @onAfterClose="onAfterClose"
    ></SendModal>
    <AddressModal
      ref="addressModal"
      v-if="isShowAddressModal"
      :visible.sync="isShowAddressModal"
      :orderId="orderId"
      @onAfterClose="onAfterClose"
    ></AddressModal>
    <OrderPrintModal
      :visible.sync="isShowPrintModal"
      :order="orderInfo"
      :print_setting="print_setting"
    ></OrderPrintModal>
    <!-- 绑定商品的弹窗 -->
    <a-modal
      title="转单列表"
      width="800px"
      :afterClose="closeModal"
      v-model="showTrans"
      :destroyOnClose="true"
      :footer="null"
    >
      <a-row v-for="(item, index) in transOrderList" :key="index" style="margin-bottom: 15px">
        <a-row type="flex" justify="space-between">
          <a-col> 供货商:{{ item.cloud_supplier_name }} </a-col>
          <a-col>
            <a-button type="link" @click="startTrans(item)" :disabled="item.cloud_order_status">{{
              item.cloud_order_status ? '已转单' : '开始转单'
            }}</a-button>
          </a-col>
        </a-row>
        <a-row v-for="(el, inx) in item.goods_info" :key="inx" type="flex">
          <a-col>
            <img
              :src="el.goods_pic || el.pic || 'https://cyy-desc.oss-cn-beijing.aliyuncs.com/sp210329_163447.png'"
              style="width: 48px; height: 48px; border-radius: 4px; margin-right: 16px; display: block"
            />
          </a-col>
          <a-col>
            <h4 class="over_e" style="font-weight: bold">{{ el.name }}</h4>
            <div class="over_e">
              规格：{{ el.attr_list ? el.attr_list.map((e) => e.attr_name).join() || '默认' : '默认' }}
            </div>
          </a-col>
        </a-row>
        <a-row style="margin-top: 10px"> 总计:￥{{ item.pay_price }} </a-row>
      </a-row>
    </a-modal>

    <!-- 绑定商品的弹窗 -->
    <a-modal
      title="转单记录"
      width="800px"
      :afterClose="closeModal"
      v-model="showTransRecord"
      :destroyOnClose="true"
      :footer="null"
    >
      <a-table style="width: 100%" :columns="transRecordColumns" :data-source="transOrderRecordList">
        <template slot="name" slot-scope="name">
          <div class="transRecordList">
            <div class="item" v-for="(item, index) of name.goods_list" :key="index">
              <div class="img">
                <img :src="item.pic_url" alt="" />
              </div>
              <div class="txt">
                <div class="name">{{ item.name }}</div>
                <div class="">
                  <div>
                    规格：
                    {{ getAttr(item) }}
                  </div>
                  <div>
                    <em>价格：{{ item.price }}</em>
                    <em>数量:x{{ item.num }}</em>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </template>
        <template slot="goods_send_type" slot-scope="name">
          {{ sendType[name] || '-' }}
        </template>
        <template slot="status" slot-scope="name">
          <span v-if="name.goods_send_type !== '1'">
            {{ getStatus2(name.status) }}
          </span>
          <span v-else>
            {{ getCentralized(name.centralized_status) }}
          </span>
        </template>
      </a-table>
    </a-modal>

    <!-- 修改价格弹框 -->
    <a-modal title="修改支付金额" v-model="changePricePop" @ok="changePriceSubmit" :confirmLoading="btnLoading">
      <a-form-model
        ref="changePriceRuleForm"
        :model="changePriceForm"
        :rules="changePriceRules"
        :label-col="{ span: 4 }"
        :wrapper-col="{ span: 18 }"
      >
        <a-form-model-item label="支付金额" prop="pay_price">
          <a-input-number v-model="changePriceForm.pay_price" :precision="2" :min="0"></a-input-number>
        </a-form-model-item>
      </a-form-model>
    </a-modal>
  </page-header-wrapper>
</template>

<script>
import SendModal from './components/SendModal'
import ModifyLogistics from './components/ModifyLogistics.vue'
import AddressModal from './components/AddressModal'
import OrderPrintModal from './components/OrderPrint'
import NoBorderRadio from '@/components/NoBorderRadio/NoBorderRadio'
import SearchBox from './components/SearchBox'
import { creatTrans, transOrderStatus, getPurchaseOrderList } from '@/api/purchase/business'

import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
import moment from 'moment'
import { Pagination } from 'ant-design-vue'
import ListTable from './components/ListTable'
import {
  modifyPrice,
  getOrderList,
  expgetOrderList,
  orderCancel,
  setComments,
  setAddress,
  orderSend,
  orderConfirm,
  orderPrint,
  orderClerk,
  orderTable,
  orderEdit,
} from '@/api/order'
export default {
  name: 'OrderList',
  components: {
    ListTable,
    Pagination,
    SendModal,
    AddressModal,
    OrderPrintModal,
    NoBorderRadio,
    SearchBox,
    ModifyLogistics,
  },
  data() {
    return {
      // 订单打印设置
      print_setting: {
        note_show: 0,
        note: '',
        qrcode_show: 0,
        not_pay_notice: '',
        pay_notice: '',
      },
      exporting: false,
      options: [
        {
          title: '全部',
          value: -1,
        },
        {
          title: '未付款',
          value: 0,
        },
        {
          title: '待退款',
          value: 7
        },
        {
          title: '待发货',
          value: 1,
        },
        {
          title: '已发货',
          value: 2,
        },
        {
          title: '已完成',
          value: 3,
        },
        {
          title: '待处理',
          value: 6,
        },
        {
          title: '已取消',
          value: 5,
        },
        {
          title: '回收站',
          value: 999,
        },
        
      ],
      spinning: false,
      expressList: [],
      list_th: [
        { type: 'list', title: '商品信息', span: 4 },
        { type: 'list', title: '单价/数量', span: 3 },
        { type: 'list', title: '运费/优惠', span: 2 },
        { type: 'list', title: '订单金额', span: 2 },
        { type: 'list', title: '买家/收货人', span: 3 },
        { type: 'list', title: '下单门店/时间', span: 3 },
        { type: 'list', title: '订单状态', span: 2 },
        {
          type: 'list',
          title: '操作',
          span: 3,
          actions: [
            '编辑',
            '发货',
            '取消',
            '核销',
            '确认收货',
            '订单打印',
            '小票打印',
            '添加备注',
            '移入回收站',
            '改价',
          ],
        },
      ],
      activeKey: '1',
      locale: zhCN,
      ranges: {
        一月内: () => [moment().startOf('day').subtract(1, 'month'), moment()],
        昨天: () => [moment().startOf('day').subtract(1, 'days'), moment().endOf('day').subtract(1, 'days')],
        最近一周: () => [moment().startOf('day').subtract(1, 'weeks'), moment()],
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      queryParam: {
        // 订单号
        // 商品名称
        // 手机号
      },
      selectDate: {},
      totalCount: 0,
      pageParams: {
        pageNo: 1,
        pageSize: 10,
      },
      pagaData: [],
      remark: '',
      isShowSendModal: false,
      isShowAddressModal: false,
      orderId: '',
      isShowPrintModal: false,
      orderInfo: null,
      // 是否显示转单
      showTrans: false,
      // 转单列表数据
      transOrderList: [],
      transOrderRecordList: [],
      showTransRecord: false,
      transRecordColumns: [
        {
          title: '商品信息',
          scopedSlots: {
            customRender: 'name',
          },
        },
        {
          title: '订单号',
          dataIndex: 'order_no',
        },
        {
          title: '配送方式',
          dataIndex: 'goods_send_type',
          scopedSlots: {
            customRender: 'goods_send_type',
          },
          width: 100,
        },
        {
          title: '状态',
          scopedSlots: {
            customRender: 'status',
          },
          width: 100,
        },
      ],
      is_cloud: false,
      sendType: ['快递', '集采', '自主配送', '代理配送'],

      changePricePop: false,
      changePriceForm: {
        pay_price: '0',
        order_id: '',
      },
      changePriceRules: {
        pay_price: [{ required: true, message: '请输入', trigger: 'blur' }],
      },
      btnLoading: false,

      isShowModifyLogistics: false,
    }
  },
  watch: {
    currentPage() {
      this.getOrderListData()
    },
  },
  created() {
    this.getOrderListData()
  },
  activated() {},
  computed: {
    currentPage() {
      return this.pageParams.pageNo || 1
    },
    getStatus2() {
      return (status) => {
        let str

        switch (status) {
          case '0':
            str = '待确认'
            break

          case '1':
            str = '已发货'
            break

          case '2':
            str = '已完成'
            break
        }

        return str
      }
    },
    getCentralized() {
      return (centralized_status) => {
        let str

        switch (parseInt(centralized_status)) {
          case 0:
            str = '待处理'
            break

          case 1:
            str = '已生成配货单'
            break

          case 2:
            str = '供货商已发往中央仓'
            break

          case 3:
            str = '中央仓已收货'
            break

          case 4:
            str = '拣货完成'
            break
        }

        return str
      }
    },
    getAttr() {
      return (item) => {
        return item.attr.attr_list
          .map((el) => {
            return el.attr_name
          })
          .join('-')
      }
    },
  },
  filters: {},
  methods: {
    // 点击搜索按钮
    search(e) {
      console.log(e)
      this.queryParam = e
      this.getOrderListData(true)
    },
    listActions(name, row, reason) {
      switch (name) {
        case 'order_edit': //编辑
          this.$router.push({ path: '/order/order-details-new', query: { order_id: row.id } })
          break
        case 'change_modifyLog':
          this.orderId = row.id
          this.orderInfo = row
          this.isShowModifyLogistics = true
          break
        case 'order_send': //发货
          this.orderId = row.id
          this.orderInfo = row
          this.isShowSendModal = true
          break
        case 'order_cancel': //取消
          this.cancel(row, 1, 1, reason)
          break
        case 'order_cancel_0': //取消
          this.cancel(row, 0, 0, reason)
          break
        case 'order_cancel_1': //取消
          this.cancel(row, 1, 0, reason)
          break
        case 'order_cancel_2': //拒绝
          this.cancel(row, 2, 0, reason)
          break
        case 'order_cancel_verification': //核销
          this.clerk(row.id)
          break
        case 'order_confirm': //确认收货
          this.confirm(row.id)
          break
        case 'order_print': //打印订单
          console.log(name)
          this.orderInfo = row
          this.isShowPrintModal = true
          this.getOrdeDetailInfo(row)
          // this.orderTable(row)
          break
        case 'order_receipts_print': //打印小票
          console.log(name)
          this.orderPrint(row)
          break
        case 'order_remark': //添加备注
          this.orderRemark(row)
          break
        case 'order_recycle': //移入回收站
          console.log(name)
          this.orderRecycle(row)
          break
        case 'order_address': //修改地址
          this.orderId = row.id
          this.isShowAddressModal = true
          break
        case 'apply_0': //拒绝取消
          console.log(name)
          break
        case 'apply_1': //同意取消
          console.log(name)
          break
        case 'transOrderSupplier': //同意取消
          this.transOrderSupplier(row)
          break
        case 'see':
          const hide = this.$message.loading('确认中...', 0)

          getPurchaseOrderList({
            order_id: row.id,
          })
            .then((res) => {
              hide()
              if (!res.code) {
                this.transOrderRecordList = res.data.list || []
                this.showTransRecord = true
              }
            })
            .catch((res) => {
              hide()
            })
          break

        case 'change_price':
          this.changePriceForm = {
            pay_price: row.pay_price,
            order_id: row.id,
          }
          this.changePricePop = true
          break

        default:
          break
      }
    },
    // 请求获取订单详情数据
    getOrdeDetailInfo(order) {
      getOrderList({
        order_id: order.id,
      }).then((res) => {
        if (res.code !== 0) {
          this.$error({
            content: res.msg,
          })
        } else {
          this.orderInfo = res.data.data[0]
          this.isShowPrintModal = true
        }
      })
    },
    clerk(order_id) {
      var params = {
        order_id: order_id,
      }
      const hide = this.$message.loading('核销中...', 0)
      orderClerk(params)
        .then((res) => {
          console.log(res)
          hide()
          if (res.code !== 0) {
            this.$error({
              content: res.msg,
            })
          } else {
            this.$message.success('成功')
            this.getOrderListData()
          }
        })
        .catch((err) => {
          this.$message.error(err.message)
        })
    },
    confirm(order_id) {
      var params = {
        order_id: order_id,
      }
      const hide = this.$message.loading('确认中...', 0)
      orderConfirm(params)
        .then((res) => {
          console.log(res)
          hide()
          if (res.code !== 0) {
            this.$error({
              content: res.msg,
            })
          } else {
            this.$message.success('确认成功')
            this.getOrderListData()
          }
        })
        .catch((err) => {
          this.$message.error(err.message)
        })
    },
    onOptionChange(val) {
      console.log(val)
      let status = val.target.value
      if (status == '999') {
        this.queryParam.is_recycle = 1
        this.queryParam.status = ''
        this.getOrderListData()
      } else {
        this.queryParam.is_recycle = 0
        this.queryParam.status = status
        this.getOrderListData()
      }
    },
    cancel(record, status, type, reason) {
      var params = {
        type: type,
        status: status,
        remark: reason,
        id: record.id,
      }
      const hide = this.$message.loading('取消中...', 0)
      orderCancel(params)
        .then((res) => {
          console.log(res)
          hide()
          if (res.code !== 0) {
            this.$error({
              content: res.msg,
            })
          } else {
            this.$message.success('取消订单成功')
            this.getOrderListData()

            let el = this.$refs.listTable
            el.confirmLoading = false
            el.visible = false
            el.item = null
            el.reason = ''
          }
          this.$nextTick(() => {
            this.$refs['addressModal'].reason = ''
          })
        })
        .catch((err) => {
          this.$message.error(err.message)
        })
    },
    orderRemark(row) {
      const h = this.$createElement
      this.$confirm({
        icon: '<>',
        closable: true,
        width: 540,
        title: '添加备注信息',
        maskClosable: true,
        content: h('div', {}, [
          h('a-textarea', {
            props: {
              placeholder: '填写备注',
              autoSize: { minRows: 4, maxRows: 6 },
            },
            on: {
              change: (val) => {
                this.remark = val.target.value
              },
            },
          }),
        ]),
        okText: '确定',
        cancelText: '取消',
        onOk: () => {
          const hide = this.$message.loading('取消中...', 0)
          setComments({
            order_id: row.id,
            seller_comments: this.remark,
          }).then((res) => {
            hide()
            if (res.code !== 0) {
              this.$error({
                content: res.msg,
              })
            } else {
              this.$message.success(res.msg)
              this.getOrderListData()
            }
          })
        },
      })
    },
    orderRecycle(row) {
      this.$confirm({
        icon: '<>',
        closable: true,
        width: 540,
        title: '是否移入回收站',
        maskClosable: true,
        okText: '确定',
        cancelText: '取消',
        onOk: () => {
          const hide = this.$message.loading('取消中...', 0)
          orderEdit({
            order_id: row.id,
            is_recycle: 1,
          }).then((res) => {
            hide()
            if (res.code !== 0) {
              this.$error({
                content: res.msg,
              })
            } else {
              this.getOrderListData(true)
              this.$message.success(res.msg)
            }
          })
        },
      })
    },
    getOrderListData(flag) {
      this.spinning = true
      if (flag) {
        this.pageParams.pageNo = 1
      }
      let params = {
        ...this.queryParam,
        ...this.pageParams,
      }
      getOrderList(params).then((res) => {
        if (res.code === 0) {
          this.expressList = res.data.express_list
          this.pagaData = res.data.data
          this.totalCount = res.data.totalCount
          this.is_cloud = res.data.is_cloud
          this.print_setting = res.data.print_setting
        } else {
          that.$message.error(res.msg)
        }
        this.spinning = false
      })
    },
    exportOL() {
      this.exporting = true
      console.log('aaa2')
      let parameter = { ...this.queryParam, ...this.pageParams }
      Object.assign(parameter, {
        pageNo: 1,
        pageSize: 100000,
        _filename: '订单记录.xlsx',
        export: 1,
      })
      expgetOrderList(parameter).then(() => {
        this.exporting = false
      })
    },
    resetSearchForm() {
      this.queryParam = {
        dateStart: moment(new Date()),
        dateEnd: moment(new Date()),
      }
    },
    moment,
    calendarChange(date, dateString) {
      this.selectDate = date[0]
    },
    onChange(date, dateString) {
      this.queryParam.dateStart = dateString[0]
      this.queryParam.dateEnd = dateString[1]
    },
    onAfterClose() {
      this.getOrderListData()
    },
    orderPrint(order) {
      const hide = this.$message.loading('提交中...', 0)
      orderPrint({
        order_id: order.id,
      }).then((res) => {
        hide()
        if (res.code !== 0) {
          this.$error({
            content: res.msg,
          })
        } else {
          this.$message.success(res.msg)
        }
      })
    },
    orderTable(order) {
      const hide = this.$message.loading('提交中...', 0)
      orderTable({
        order_id: order.id,
      }).then((res) => {
        hide()
        if (res.code !== 0) {
          this.$error({
            content: res.msg,
          })
        } else {
          this.getOrderListData()
          this.$message.success(res.msg)
        }
      })
    },
    // 用户点击转单
    transOrderSupplier(row) {
      let goodsList = JSON.parse(JSON.stringify(row.goods_list))
      // let goodsList = [
      //   {
      //     name: '商品1',
      //     attr_list:[{attr_group_id: "21", attr_group_name: "尺码", attr_id: "78", attr_name: "S"},{attr_group_id: "10", attr_group_name: "颜色分类", attr_id: "239", attr_name: "白色"}],
      //     num:'2',
      //     goods_id:'668',
      //     cloud_bind:
      //       '{"cloud_goods_id":4,"cloud_attr_id":5,"cloud_supplier_id":7,"cloud_supplier_name":"\\u6d4b\\u8bd5\\u521b\\u5efa111","cloud_supplier_logo":"https:\\/\\/chidian.cyyvip.com\\/web\\/uploads\\/images\\/store_1\\/2022-03-12\\/8a3cbe2ab083b1d823da283817a70a85d1788672.jpg"}',
      //   },
      //   {
      //     name: '商品2',
      //     attr_list:[{attr_group_id: "21", attr_group_name: "尺码", attr_id: "78", attr_name: "S"},{attr_group_id: "10", attr_group_name: "颜色分类", attr_id: "239", attr_name: "白色"}],
      //     num:'2',
      //     goods_id:'668',
      //     cloud_bind:
      //       '{"cloud_goods_id":4,"cloud_attr_id":5,"cloud_supplier_id":7,"cloud_supplier_name":"\\u6d4b\\u8bd5\\u521b\\u5efa111","cloud_supplier_logo":"https:\\/\\/chidian.cyyvip.com\\/web\\/uploads\\/images\\/store_1\\/2022-03-12\\/8a3cbe2ab083b1d823da283817a70a85d1788672.jpg"}',
      //   },
      //   {
      //     name: '商品3',
      //     attr_list:[{attr_group_id: "21", attr_group_name: "尺码", attr_id: "78", attr_name: "S"},{attr_group_id: "10", attr_group_name: "颜色分类", attr_id: "239", attr_name: "白色"}],
      //     num:'2',
      //     goods_id:'668',
      //     cloud_bind:
      //       '{"cloud_goods_id":4,"cloud_attr_id":5,"cloud_supplier_id":7,"cloud_supplier_name":"\\u6d4b\\u8bd5\\u521b\\u5efa111","cloud_supplier_logo":"https:\\/\\/chidian.cyyvip.com\\/web\\/uploads\\/images\\/store_1\\/2022-03-12\\/8a3cbe2ab083b1d823da283817a70a85d1788672.jpg"}',
      //   },
      //   {
      //     name: '商品4',
      //     attr_list:[{attr_group_id: "21", attr_group_name: "尺码", attr_id: "78", attr_name: "S"},{attr_group_id: "10", attr_group_name: "颜色分类", attr_id: "239", attr_name: "白色"}],
      //     num:'2',
      //     goods_id:'666',
      //     cloud_bind:
      //       '{"cloud_goods_id":4,"cloud_attr_id":5,"cloud_supplier_id":8,"cloud_supplier_name":"\\u6d4b\\u8bd5\\u521b\\u5efa122","cloud_supplier_logo":"https:\\/\\/chidian.cyyvip.com\\/web\\/uploads\\/images\\/store_1\\/2022-03-12\\/8a3cbe2ab083b1d823da283817a70a85d1788672.jpg"}',
      //   },
      //   {
      //     name: '商品5',
      //     goods_id:'621',
      //     attr_list:[{attr_group_id: "21", attr_group_name: "尺码", attr_id: "78", attr_name: "S"},{attr_group_id: "10", attr_group_name: "颜色分类", attr_id: "239", attr_name: "白色"}],
      //     num:'2',
      //     cloud_bind:
      //       '{"cloud_goods_id":4,"cloud_attr_id":5,"cloud_supplier_id":9,"cloud_supplier_name":"\\u6d4b\\u8bd5\\u521b\\u5efa123","cloud_supplier_logo":"https:\\/\\/chidian.cyyvip.com\\/web\\/uploads\\/images\\/store_1\\/2022-03-12\\/8a3cbe2ab083b1d823da283817a70a85d1788672.jpg"}',
      //   },
      // ]
      // 把订单商品处理成可以转单的数据格式
      var map = {},
        dest = []
      goodsList.forEach((item) => {
        if (item.cloud_bind) {
          if (typeof item.cloud_bind !== 'object') {
            item.cloud_bind = JSON.parse(item.cloud_bind)
          }
          var cloud = item.cloud_bind
          if (!map[cloud.cloud_supplier_id]) {
            dest.push({
              province_id: row.province_id,
              city_id: row.city_id,
              district_id: row.district_id,
              address: row.address,
              name: row.name,
              tel: row.mobile,
              cloud_supplier_id: cloud.cloud_supplier_id,
              cloud_supplier_name: cloud.cloud_supplier_name,
              goods_info: [item],
              order_id: row.id,
            })
            map[cloud.cloud_supplier_id] = item
          } else {
            dest.forEach((cloudItem) => {
              if (cloudItem.cloud_supplier_id == item.cloud_bind.cloud_supplier_id) {
                cloudItem.goods_info.push(item)
              }
            })
          }
        }
      })

      // 批量申请转单的价格和状态
      let transStatus = JSON.parse(JSON.stringify(dest))
      let goodsArr = []
      transStatus.forEach((item) => {
        let goods_info = item.goods_info
        goods_info.forEach((good) => {
          let attr = good.attr_list.map((attr) => {
            return attr.attr_id
          })
          goodsArr.push({
            goods_id: good.goods_id + '-' + attr.join('-'),
            attr_id: good.cloud_bind.cloud_attr_id,
            num: good.num,
          })
        })
      })
      if (transStatus.length) {
        let supplier = transStatus[0]
        let statusParam = {
          province_id: supplier.province_id,
          city_id: supplier.city_id,
          district_id: supplier.district_id,
          address: supplier.address,
          name: supplier.name,
          tel: supplier.tel,
          goods_info: goodsArr,
          order_id: supplier.order_id,
        }

        this.transOrderStatus(statusParam, dest)
      }

      return
    },
    // 点击开始转单
    async startTrans(item) {
      console.log(item)
      let goods_info = []
      item.goods_info.forEach((item) => {
        if (!Array.isArray(item.attr_list)) {
          item.attr_list = JSON.parse(item.attr_list)
        }
        let goods_attr = []
        item.attr_list.forEach((attr) => {
          goods_attr.push(attr.attr_id)
        })
        goods_info.push({
          goods_id: item.goods_id,
          goods_attr: goods_attr.join('-'),
          cloud_goods_id: item.cloud_bind.cloud_goods_id,
          cloud_goods_attr: item.cloud_bind.cloud_attr_id,
          num: item.num,
        })
      })
      let param = {
        province_id: item.province_id,
        city_id: item.city_id,
        district_id: item.district_id,
        address: item.address,
        name: item.name,
        tel: item.tel,
        cloud_supplier_id: item.cloud_supplier_id,
        order_id: item.order_id,
        goods_info: JSON.stringify(goods_info),
      }
      console.log(param)
      const res = await creatTrans(param)
      if (res.code == 0) {
        this.$message.success(res.msg)
        this.showTrans = false
        this.getOrderListData(false)

        return
      }

      this.$message.error(res.msg)
    },
    // 关闭转单弹窗
    closeModal() {
      this.transOrderList = []
    },
    // 查询转单的价格和状态
    async transOrderStatus(params, arr) {
      params.goods_info = JSON.stringify(params.goods_info)
      const res = await transOrderStatus(params)
      if (res.code == 0) {
        console.log(res)
        let supplierArr = res.data
        arr.forEach((item) => {
          supplierArr.forEach((supplier) => {
            if (item.cloud_supplier_id == supplier.supplier.id) {
              item.express_price = supplier.express_price
              item.pay_price = supplier.pay_price
              item.cloud_order_status = supplier.cloud_order_status
            }
          })
        })
        this.transOrderList = arr
        this.showTrans = true
      }
    },

    // 修改支付价格
    changePriceSubmit() {
      this.$refs['changePriceRuleForm'].validate(async (valid) => {
        if (valid) {
          let { changePriceForm } = this

          this.btnLoading = true
          let res = await modifyPrice(changePriceForm)
          if (res.code == 0) {
            this.$message.success('修改成功')
            this.changePricePop = false
            this.getOrderListData()
          } else {
            this.$message.error(res.msg)
          }
          this.btnLoading = false
        } else {
          return false
        }
      })
    },
  },
}
</script>
<style lang="less" scoped>
/deep/.ant-card-head {
  border-bottom: none;
}
.top_card {
  /deep/.ant-card-body {
    padding-bottom: 0;
  }
  /deep/.ant-tabs-bar {
    margin-bottom: 0;
    border-bottom: 1px solid #fff;
  }
}
.over_e {
  width: 192px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.transRecordList {
  .item {
    display: flex;
  }

  .img {
    margin-right: 10px;
    width: 80px;
    height: 80px;

    img {
      display: block;
      width: 100%;
      height: 100%;
    }
  }

  .txt {
    flex: 1;
    overflow: hidden;

    em {
      margin-right: 6px;
      font-style: normal;
    }
  }
}
</style>
